package org.reference.generic;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.reference.generic.base.Manager;
import org.reference.generic.base.Parameter;
import org.reference.generic.information.Gene;
import org.reference.generic.work.Job;
import org.reference.generic.work.Machine;
import org.reference.generic.work.MachineManager;
import org.reference.generic.work.Schedule;
import org.reference.generic.work.ScheduleManager;



/**
 * 
 */
public class Process extends Manager {

    /**
     * 
     */
    public Process( ) {
    }

    /**
     * 
     */
    private MachineManager machineManager;

    /**
     * 
     */
    private Parameter crossOverRate;

    /**
     * 
     */
    private Parameter referenceCmax;

    /**
     * 
     */
    private Parameter mutationRate;

    /**
     * 
     */
    private Parameter reproductionRate;

    /**
     * 
     */
    private Parameter maxDepth;
    
    /**
     * 
     */
    private Parameter arity;
  
  
   // Map<String, Parameter> params = new HashMap<String, Parameter>();
    
    /**
     * 
     */
    private OnCompleteListenner onMachineManagerCompleteListenner;

	@Override
	public void init(Parameter[] parameters) {

//		for(Parameter param: parameters){
//		params.put(param.getName(), param);
//				
//		}
		
		for (Parameter param: parameters) {
			if(param.getName().equalsIgnoreCase(Parameter.TYPE_ARITY)) {
				arity = new Parameter();
				arity.setValue(param.getValue());
			}
			
			else if(param.getName().equalsIgnoreCase(Parameter.TYPE_MAX_DEPTH)){
				maxDepth = new Parameter();
				maxDepth.setValue(param.getValue());
			}
			
			else if(param.getName().equalsIgnoreCase(Parameter.TYPE_REPRODUCTION_RATE)){
				reproductionRate = new Parameter();
				reproductionRate.setValue(param.getValue());
			}
			
			else if(param.getName().equalsIgnoreCase(Parameter.TYPE_REFERENCE_CMAX)){
				referenceCmax = new Parameter();
				referenceCmax.setValue(param.getValue());
			}
			else if(param.getName().equalsIgnoreCase(Parameter.TYPE_CROSSOVER_RATE)){
				crossOverRate = new Parameter();
				crossOverRate.setValue(param.getValue());
			}
			else if(param.getName().equalsIgnoreCase(Parameter.TYPE_MUTATION_RATE)){
				mutationRate = new Parameter();
				mutationRate.setValue(param.getValue());
			}
			
			else if(param.getName().equalsIgnoreCase(Parameter.TYPE_GENE_POPULATION)) {  // gene 갯수 만큼 생성... 
				for(int i=0 ; i<param.getValueToInt(); i++){
					Gene gene = new Gene(parameters);    //gene 생성 
					Schedule schedule = new Schedule();  //gene만큼 schedule 생성  
					schedule.setGene(gene);            //schedule에다가 gene 대입 
					itemList.add(gene);					// gene 리스트로 관리 
					
					if(param.getName().equalsIgnoreCase(Parameter.TYPE_JOB_NUMBER)) {   
						for(int j=0 ; j<param.getValueToInt(); j++){
							Job job = new Job();				// 잡을 생성
							itemList.add(job);					// 잡 리스트 화 
							schedule.setJobList(itemList);		// 스케줄에 잡 리스트 대입  
					}
				}
			
					
					
			}
		}
			
			
	}

		machineManager = new MachineManager();
		machineManager.setOnCompleteListenner(onMachineManagerCompleteListenner);
		machineManager.init(parameters);
		
		
		//ScheduleManager sm = new ScheduleManager();
		//sm.init(parameters);
		
		
	}
				
	@Override
	public Parameter[] getResult() {
		// TODO Auto-generated method stub
		return null;
	}
	
//	public void run(Schedule schedule){
//		
//		machineManager.run(schedule);
//		
//	}
	

}